if(typeof BX.InterfaceGridFilter==="undefined"){BX.InterfaceGridFilter=function(){this._defaultItemId="";this._id="";this._settings=null;this._itemInfos={};this._fieldInfos={};this._visibleFieldCount=0;this._items={};this._fields={};this._addFieldOpener=null;this._settingsOpener=null;this._ignoreFieldVisibilityChange=false;this._isApplied=false;this._currentItemId="";this._activeItemId="";this._saveAsDlg=null;this._enableProvider=true;this._fieldProvider=null;this._isFolded=false;this._presetsDeleted=[];this._saveVisibleFieldsTimeoutId=null;this._closeOpen=null};BX.InterfaceGridFilter.prototype={initialize:function(e,t){this._id=BX.type.isNotEmptyString(e)?e:"";this._settings=t?t:BX.ParamBag.create(null);this._isApplied=this._settings.getParam("isApplied",false);this._isFolded=this._settings.getParam("isFolded",true);this._presetsDeleted=this._settings.getParam("presetsDeleted",[]);this._defaultItemId=this._settings.getParam("defaultItemId","filter_default");this._currentItemId=this._settings.getParam("currentItemId","");this._activeItemId=this._currentItemId;if(this._activeItemId===""){this._activeItemId=this._defaultItemId}this._itemInfos=this._settings.getParam("itemInfos",{});var i=this._settings.getParam("currentValues",{});if(BX.type.isArray(i)){i={}}var n=this._activeItemId===this._defaultItemId;this._items[this._defaultItemId]=BX.InterfaceGridFilterItem.create(this._defaultItemId,BX.ParamBag.create({filter:this,info:{name:"",fields:n?i:{},filter_rows:this._settings.getParam("defaultVisibleRows","")},isActive:n}));for(var s in this._itemInfos){if(!this._itemInfos.hasOwnProperty(s)||s===this._defaultItemId||this.isDeleletedPreset(s)){continue}this._items[s]=BX.InterfaceGridFilterItem.create(s,BX.ParamBag.create({filter:this,info:this._itemInfos[s],isActive:this._activeItemId===s}))}this._fieldInfos=this._settings.getParam("fieldInfos",{});for(var r in this._fieldInfos){if(!this._fieldInfos.hasOwnProperty(r)){continue}var a=BX.InterfaceGridFilterField.create(r,BX.ParamBag.create({filter:this,info:this._fieldInfos[r]}));this._fields[r]=a;if(a.isVisible()){this._visibleFieldCount++}}BX.bind(this.getAddFieldButton(),"click",BX.delegate(this._handleAddFieldButtonClick,this));BX.bind(this.getSettingsButton(),"click",BX.delegate(this._handleSettingsButtonClick,this));BX.bind(this.getApplyButton(),"click",BX.delegate(this._handleApplyButtonClick,this));BX.bind(this.getCancelButton(),"click",BX.delegate(this._handleCancelButtonClick,this));BX.bind(this.getAddFilterButton(),"click",BX.delegate(this._handleSaveAsMenuItemClick,this));this._closeOpen=new BX.InterfaceGridFilterCloseOpen(this._settings.getParam("innerBlock",""),this._settings.getParam("mainBlock",""),this);this._closeOpen.initialize();var l=this.getSwitchViewButton();if(l){l.title=this.getMessage(this._isFolded?"buttonMaximize":"buttonMinimize");BX.bind(l,"click",BX.delegate(this._handleSwitchViewButtonClick,this))}this._enableProvider=this._settings.getParam("enableProvider",false);if(this._enableProvider){this._fieldProvider=BX.InterfaceFilterFieldInfoProvider.items[this.getGridId()];if(this._fieldProvider){this._initializeFieldControllers()}else{this._fieldProvider=null;BX.addCustomEvent(window,"InterfaceFilterFieldInfoProviderCreate",BX.delegate(this._onFieldInfoProviderCreated,this))}}},_onFieldInfoProviderCreated:function(e){if(e.getId()===this.getGridId()){this._fieldProvider=e;this._initializeFieldControllers()}},_initializeFieldControllers:function(){for(var e in this._fields){if(this._fields.hasOwnProperty(e)){this._fields[e].initializeController()}}},getMessage:function(e){return BX.InterfaceGridFilter.getMessage(e)},getId:function(){return this._id},isApplied:function(){return this._isApplied},isFolded:function(){return this._isFolded},getCurrentItemId:function(){return this._currentItemId},getGridId:function(){return this._settings.getParam("gridId","")},getFormName:function(){return this._settings.getParam("formName","")},getForm:function(){return document.forms[this.getFormName()]},getCurrentTime:function(){return this._settings.getParam("currentTime","")},getServiceUrl:function(){return this._settings.getParam("serviceUrl","")},getContainerId:function(){return this._settings.getParam("containerId","flt_wrapper")},getItemContainerId:function(e){return this._settings.getParam("itemContainerPrefix","flt_tab_")+e.toString()},getFieldContainerId:function(e){return this._settings.getParam("fieldContainerPrefix","flt_field_")+e.toString()},getFieldDelimiterContainerId:function(e){return this._settings.getParam("fieldDelimiterContainerPrefix","flt_field_delim_")+e.toString()},getVisibleFieldCount:function(){return this._visibleFieldCount},getVisibleFieldIds:function(){var e=[];var t=this._fields;for(var i in t){if(t.hasOwnProperty(i)&&t[i].isVisible()){e.push(i)}}return e},getFieldInfo:function(e){if(!this._fieldProvider){return null}var t=this._fieldProvider.getFieldInfos();if(!t){return null}for(var i=0;i<t.length;i++){if(t[i]["id"]===e){return t[i]}}return null},saveVisibleFields:function(){if(this._saveVisibleFieldsTimeoutId!==null){window.clearTimeout(this._saveVisibleFieldsTimeoutId);this._saveVisibleFieldsTimeoutId=null}var e=this;this._saveVisibleFieldsTimeoutId=window.setTimeout(function(){e._doSaveVisibleFields()},100)},_doSaveVisibleFields:function(){this._saveVisibleFieldsTimeoutId=null;BX.ajax.get(this.getServiceUrl(),{GRID_ID:this.getGridId(),action:"filterrows",filter_id:this._activeItemId!==this._defaultItemId?this._activeItemId:"",rows:this.getVisibleFieldIds().join(",")})},saveActiveItem:function(e){var t=this._items[this._activeItemId];if(!t){return}BX.ajax.post(this.getServiceUrl(),{GRID_ID:this.getGridId(),filter_id:t.getId(),action:"savefilter",name:t.getName(),fields:this.getFieldParams(),rows:this.getVisibleFieldIds().join(",")},e)},isDeleletedPreset:function(e){for(var t=0;t<this._presetsDeleted.length;t++){if(this._presetsDeleted[t]===e){return true}}return false},deleteActiveItem:function(){var e=this._items[this._activeItemId];if(!e){return}var t=e.getId();BX.ajax.post(this.getServiceUrl(),{GRID_ID:this.getGridId(),filter_id:t,action:"delfilter"});if(/^filter_[0-9]+$/i.test(t)||this.isDeleletedPreset(t)){return}this._presetsDeleted.push(t);var i=BX.userOptions.delay;BX.userOptions.delay=100;BX.userOptions.save("main.interface.grid.filter",this.getId().toLowerCase(),"presetsDeleted",this._presetsDeleted.join(","));BX.userOptions.delay=i},requireFieldVisibilityChange:function(e){if(this._ignoreFieldVisibilityChange){return true}return!e.isVisible()||this.getVisibleFieldCount()>1},handleFieldVisibilityChange:function(e){if(this._ignoreFieldVisibilityChange){return}if(e.isVisible()){this._visibleFieldCount++}else{this._visibleFieldCount--}this._adjustStyle();this._showDeleteButtons(this._visibleFieldCount>1);this.saveVisibleFields()},requireItemActivityChange:function(e){return true},handleItemActivityChange:function(e){if(!e.isActive()){return}this._setActiveItem(e)},handleSaveAsDialogClose:function(e){if(e.getButtonId()!=="save"){return}var t=e.getValues();var i="filter_"+Math.random().toString().substring(2).toString();var n={name:t["name"]?t["name"]:BX.InterfaceGridFilter.getMessage("defaultFilterName"),fields:this.getFieldParams()};this._itemInfos[i]=n;var s=this._items[i]=BX.InterfaceGridFilterItem.create(i,BX.ParamBag.create({filter:this,info:n,isActive:false}));s.setActive(true);this.saveActiveItem()},getFieldParams:function(){var e={};for(var t in this._fields){if(this._fields.hasOwnProperty(t)){this._fields[t].getParams(e)}}return e},setFieldParams:function(e){for(var t in this._fields){if(this._fields.hasOwnProperty(t)){this._fields[t].setParams(e)}}},_setActiveItem:function(e){var t=null;if(this._activeItemId!==""){t=this._items[this._activeItemId]}if(t){t.setFieldParams(this.getFieldParams());t.setVisibleFieldIds(this.getVisibleFieldIds());t.setActive(false)}this._activeItemId=e.getId();t=this._items[this._activeItemId];var i=this._getWrapper();if(t.isCurrent()){if(this.isApplied())BX.addClass(i,"bx-current-filter")}else{BX.removeClass(i,"bx-current-filter")}this.setFieldParams(t.getFieldParams());this._ignoreFieldVisibilityChange=true;this._visibleFieldCount=0;var n=t.getVisibleFieldIds();if(n.length>0){for(var s in this._fields){if(!this._fields.hasOwnProperty(s)){continue}var r=false;for(var a=0;a<n.length;a++){if(n[a]===s){r=true;break}}this._fields[s].setVisible(r);if(r){this._visibleFieldCount++}}}else{for(var s in this._fieldInfos){if(!this._fieldInfos.hasOwnProperty(s)){continue}var r=this._fieldInfos[s]["isVisible"];this._fields[s].setVisible(r);if(r){this._visibleFieldCount++}}}this._adjustStyle();this._showDeleteButtons(this._visibleFieldCount>1);this._ignoreFieldVisibilityChange=false},apply:function(e){var t=this._items[e];if(t){this._setActiveItem(t);this.applyActive()}},applyActive:function(){var e=this._currentItemId;this._currentItemId=this._activeItemId;if(e!==""){this._items[e].handleCurrentItemChange(this)}this._items[this._currentItemId].handleCurrentItemChange(this);var t=this.getForm();if(!t){return}var i=BX.findChild(t,{tag:"INPUT",property:{type:"hidden",name:"grid_filter_id"}},true,false);if(i){i.value=this._activeItemId!==this._defaultItemId?this._activeItemId:""}var n=BX.findChild(t,{tag:"INPUT",property:{type:"hidden",name:"apply_filter"}},true,false);if(n){n.value="Y"}BX.submit(t)},clear:function(){var e=this.getForm();if(!e){return}var t=BX.findChild(e,{tag:"INPUT",property:{type:"hidden",name:"clear_filter"}},true,false);if(t){t.value="Y"}this.setFieldParams({});BX.submit(e)},_adjustStyle:function(){var e=BX(this.getContainerId());if(!e){return}var t=BX.findChild(e,{"class":"bx-filter-bottom-separate"},true,false);var i=BX.findChild(e,{"class":"bx-filter-content"},true,false);if(this.getVisibleFieldCount()>1){BX.removeClass(i,"bx-filter-content-first");t.style.display=""}else{BX.addClass(i,"bx-filter-content-first");t.style.display="none"}},_getWrapper:function(){return BX.findChild(BX(this.getContainerId()),{tag:"DIV","class":"bx-filter-wrap"},true)},getAddFieldButton:function(){return BX.findChild(BX(this.getContainerId()),{tag:"SPAN","class":"bx-filter-add-button"},true,false)},getAddFilterButton:function(){return BX.findChild(BX(this.getContainerId()),{tag:"SPAN","class":"bx-filter-add-tab"},true,false)},getSettingsButton:function(){return BX.findChild(BX(this.getContainerId()),{tag:"SPAN","class":"bx-filter-setting"},true,false)},getApplyButton:function(){return BX.findChild(BX(this.getContainerId()),{tag:"INPUT",property:{type:"button",name:"set_filter"}},true,false)},getCancelButton:function(){return BX.findChild(BX(this.getContainerId()),{tag:"INPUT",property:{type:"button",name:"reset_filter"}},true,false)},getSwitchViewButton:function(){return BX.findChild(BX(this.getContainerId()),{tag:"SPAN","class":"bx-filter-switcher-tab"},true,false)},setFieldsVisible:function(e,t){this._ignoreFieldVisibilityChange=true;this._visibleFieldCount=0;e=!!e;t=t?t:{};var i=typeof t["skipTop"]!=="undefined"?parseInt(t["skipTop"]):0;var n=this._fields;for(var s in n){if(!n.hasOwnProperty(s)){continue}var r=n[s];if(r.isVisible()!==e){if(i>0){i--}else{r.setVisible(e)}}if(r.isVisible()){this._visibleFieldCount++}}this._adjustStyle();this._showDeleteButtons(this._visibleFieldCount>1);this.saveVisibleFields();this._ignoreFieldVisibilityChange=false},setFolded:function(e){e=!!e;if(e===this._isFolded){return}this._isFolded=e;if(this._closeOpen)this._closeOpen.toggle();var t=BX(this._settings.getParam("mainBlock",""));if(e){BX.addClass(this._getWrapper(),"bx-filter-folded");if(t)t.style.height="0"}else{BX.removeClass(this._getWrapper(),"bx-filter-folded")}if(this._activeItemId!==""){var i=this._items[this._activeItemId];if(i){i.handleFilterFoldingChange(this)}}var n=this.getSwitchViewButton();if(n){n.title=this.getMessage(e?"buttonMaximize":"buttonMinimize")}var s=BX.userOptions.delay;BX.userOptions.delay=100;BX.userOptions.save("main.interface.grid.filter",this.getId().toLowerCase(),"isFolded",e?"Y":"N");BX.userOptions.delay=s},_showDeleteButtons:function(e){e=!!e;var t=this._fields;for(var i in t){if(t.hasOwnProperty(i)){t[i].showDeleteButton(e)}}},_handleAddFieldButtonClick:function(e){var t=[];var i=this._fields;for(var n in i){if(!i.hasOwnProperty(n)){continue}var s=i[n];t.push({id:s.getId(),text:s.getName(),onchange:s.getToggleHandler(),checked:s.isVisible(),tag:"field"})}t.push({id:"__showAll",text:this.getMessage("showAll"),onclick:BX.delegate(this._handleShowAllButtonClick,this),checked:false,tag:"command",allowToggle:false,separatorBefore:true});t.push({id:"__hideAll",text:this.getMessage("hideAll"),onclick:BX.delegate(this._handleHideAllButtonClick,this),checked:false,tag:"command",allowToggle:false});var r=this.getAddFieldButton();var a=BX.pos(r);this._addFieldOpener=BX.InterfaceGridFilterCheckListMenu.create(this.getId()+"_ADD_FIELDS",BX.ParamBag.create({allowToggle:true,items:t,anchor:r,offsetTop:Math.round(a.height/4),offsetLeft:Math.round(a.width/2),angle:{position:"top",offset:0}}));this._addFieldOpener.open()},_handleSettingsButtonClick:function(e){var t=[];if(this._activeItemId==this._defaultItemId){t.push({id:"saveAs",text:this.getMessage("saveAs"),onclick:BX.delegate(this._handleSaveAsMenuItemClick,this),checked:false})}else{t.push({id:"save",text:this.getMessage("save"),onclick:BX.delegate(this._handleSaveMenuItemClick,this),checked:false});t.push({id:"saveAs",text:this.getMessage("saveAs"),onclick:BX.delegate(this._handleSaveAsMenuItemClick,this),checked:false});t.push({id:"delete",text:this.getMessage("delete"),onclick:BX.delegate(this._handleDeleteMenuItemClick,this),checked:false})}var i=this.getSettingsButton();var n=BX.pos(i);this._settingsOpener=BX.InterfaceGridFilterCheckListMenu.create(this.getId()+"_SETTINGS_"+this._activeItemId.toUpperCase(),BX.ParamBag.create({allowToggle:false,items:t,anchor:i,closeOnClick:true,offsetTop:Math.round(n.height/4),offsetLeft:Math.round(n.width/2),angle:{position:"top",offset:0}}));this._settingsOpener.open()},_handleApplyButtonClick:function(e){if(this._activeItemId===this._defaultItemId){this.applyActive();return}var t=this;this.saveActiveItem(function(){t.applyActive()})},_handleCancelButtonClick:function(e){this.clear()},_handleShowAllButtonClick:function(e){if(this._addFieldOpener){var t=this._addFieldOpener.getItemsByTag("field");for(var i=0;i<t.length;i++){t[i].setChecked(true)}}this.setFieldsVisible(true,{})},_handleHideAllButtonClick:function(e){if(this._addFieldOpener){var t=this._addFieldOpener.getItemsByTag("field");for(var i=1;i<t.length;i++){t[i].setChecked(false)}}this.setFieldsVisible(false,{skipTop:1})},_handleSaveMenuItemClick:function(e){if(this._isApplied&&this._currentItemId===this._activeItemId){var t=this;this.saveActiveItem(function(){t.applyActive()})}else{this.saveActiveItem()}},_handleSaveAsMenuItemClick:function(e){if(!this._saveAsDlg){this._saveAsDlg=BX.InterfaceGridFilterSaveAsDialog.create(this.getId()+"_SAVE_AS",BX.ParamBag.create({filter:this}))}this._saveAsDlg.openDialog()},_handleDeleteMenuItemClick:function(e){var t=this._activeItemId;var i=this._items[t];if(t===this._defaultItemId||!i){return}this.deleteActiveItem();if(i.isCurrent()){this.clear()}i.clearLayout();this._items[this._defaultItemId].setActive(true);delete this._items[t]},_handleSwitchViewButtonClick:function(e){this.setFolded(!this.isFolded())}};BX.InterfaceGridFilter.isEmptyObject=function(e){if(e===null||e===undefined){return true}var t=Object.prototype.hasOwnProperty;if(typeof e.length!=="undefined"){return e.length===0}if(typeof e==="object"){for(var i in e){if(t.call(e,i)){return false}}}return true};if(typeof BX.InterfaceGridFilter.messages==="undefined"){BX.InterfaceGridFilter.messages={}}BX.InterfaceGridFilter.getMessage=function(e){return typeof BX.InterfaceGridFilter.messages[e]!=="undefined"?BX.InterfaceGridFilter.messages[e]:""};BX.InterfaceGridFilter.items={};BX.InterfaceGridFilter.create=function(e,t){var i=new BX.InterfaceGridFilter;i.initialize(e,t);this.items[e]=i;return i}}if(typeof BX.InterfaceGridFilterItem==="undefined"){BX.InterfaceGridFilterItem=function(){this._id="";this._settings=null;this._filter=null;this._container=null;this._isActive=false;this._info={};this._fieldParams={};this._visibleFieldIds=[]};BX.InterfaceGridFilterItem.prototype={initialize:function(e,t){this._id=BX.type.isNotEmptyString(e)?e:"";this._settings=t?t:BX.ParamBag.create(null);this._filter=t.getParam("filter",null);this._info=t.getParam("info",{});this._fieldParams=typeof this._info["fields"]!=="undefined"?this._info["fields"]:{};var i=typeof this._info["filter_rows"]!=="undefined"?this._info["filter_rows"]:null;if(BX.type.isString(i)){i=i.split(",")}if(BX.type.isArray(i)){this._visibleFieldIds=i}else{for(var n in this._fieldParams){if(this._fieldParams.hasOwnProperty(n)){this._visibleFieldIds.push(BX.InterfaceGridFilterField.convertParamToFieldId(n))}}}this._isActive=t.getParam("isActive",false);var s=this._filter.getItemContainerId(e);this._container=BX(s);if(!this._container){this.layout()}BX.bind(this._container,"click",BX.delegate(this._onClick,this))},getId:function(){return this._id},getName:function(){return this._info["name"]},getInfo:function(){return this._info},isActive:function(){return this._isActive},isCurrent:function(){return this._filter.getCurrentItemId()===this.getId()},setActive:function(e){e=!!e;if(this._isActive===e){return}if(!this._filter.requireItemActivityChange(this)){return}this._isActive=e;this._filter.handleItemActivityChange(this);this._adjustStyle()},getFieldParams:function(){return this._fieldParams},setFieldParams:function(e){this._fieldParams=e},getVisibleFieldIds:function(){return this._visibleFieldIds},setVisibleFieldIds:function(e){this._visibleFieldIds=e},layout:function(){var e=BX.findChild(BX(this._filter.getContainerId()),{tag:"DIV","class":"bx-filter-tabs-block"},true);if(!e){return}this._container=BX.create("SPAN",{props:{id:this._filter.getItemContainerId(this.getId())},attrs:{"class":"bx-filter-tab"},text:this.getName()});e.insertBefore(this._container,this._filter.getAddFilterButton())},clearLayout:function(){if(!this._container){return}BX.remove(this._container)},_adjustStyle:function(){if(this._filter.isFolded()){if(this.isCurrent()){BX.addClass(this._container,"bx-filter-tab-active")}else{BX.removeClass(this._container,"bx-filter-tab-active")}}else{if(this._isActive){BX.addClass(this._container,"bx-filter-tab-active")}else{BX.removeClass(this._container,"bx-filter-tab-active")}}},handleFilterFoldingChange:function(e){this._adjustStyle()},handleCurrentItemChange:function(e){this._adjustStyle()},_onClick:function(e){if(!this.isActive()){this.setActive(true)}if(this._filter.isFolded()){this._filter.applyActive()}}};BX.InterfaceGridFilterItem.create=function(e,t){var i=new BX.InterfaceGridFilterItem;i.initialize(e,t);return i}}if(typeof BX.InterfaceGridFilterField==="undefined"){BX.InterfaceGridFilterField=function(){this._id="";this._settings=null;this._filter=null;this._info={};this._container=null;this._delimiterContainer=null;this._isVisible=true;this._deleteButton=null;this._controller=null};BX.InterfaceGridFilterField.prototype={initialize:function(e,t){this._id=BX.type.isNotEmptyString(e)?e:"";this._settings=t?t:BX.ParamBag.create(null);this._filter=t.getParam("filter",null);this._container=BX(this._filter.getFieldContainerId(e));this._delimiterContainer=BX(this._filter.getFieldDelimiterContainerId(e));this._info=t.getParam("info",{});this._isVisible=this._info["isVisible"];this._deleteButton=BX.findChild(this._container,{tag:"SPAN","class":"bx-filter-item-delete"},true,false);if(this._deleteButton){this._deleteButton.title=BX.InterfaceGridFilter.getMessage("buttonDeleteField");BX.bind(this._deleteButton,"click",BX.delegate(this._handleDeleteButtonClick,this))}if(this.getType()==="date"){this._controller=BX.InterfaceGridFilterDate.create(BX.ParamBag.create({containerId:this._filter.getFieldContainerId(e),formName:this._filter.getFormName(),currentTime:this._filter.getCurrentTime()}))}if(this._controller){this._controller.layout()}this._handleVisibilityChange()},initializeController:function(){if(this.getType()!=="custom"){return}var e=this._filter.getFieldInfo(this._id);if(!e){return}var t=this._filter.getFieldContainerId(this._id);if(e.controller){this._controller=e.controller;this._controller.setContainerId(t)}else{if(e["typeName"]==="USER"){this._controller=BX.InterfaceGridFilterUser.create(BX.ParamBag.create({containerId:t,info:e}))}else if(e["typeName"]==="WIDGET_PERIOD"){this._controller=BX.InterfaceGridFilterWidgetPeriod.create(BX.ParamBag.create({containerId:t,info:e}))}}if(this._controller){this._controller.layout()}},getId:function(){return this._id},getName:function(){return this._info["name"]},getType:function(){return this._info["type"]},isVisible:function(){return this._isVisible},getToggleHandler:function(){return BX.delegate(this._handleToggleButtonClick,this)},_handleToggleButtonClick:function(e){this.toggle()},_handleDeleteButtonClick:function(e){this.setVisible(false)},_handleVisibilityChange:function(){var e=BX.findChildren(this._container,{tag:/^INPUT|SELECT|TEXTAREA/i},true);if(!BX.type.isArray(e)){return}var t=!this._isVisible;for(var i=0;i<e.length;i++){var n=e[i];var s=n.name;if(s===""){continue}n.disabled=t}},setVisible:function(e){e=!!e;if(this._isVisible===e){return}if(!this._filter.requireFieldVisibilityChange(this)){return}this._container.style.display=e?"":"none";if(this._delimiterContainer){this._delimiterContainer.style.display=e?"":"none"}this._isVisible=e;this._handleVisibilityChange();this._filter.handleFieldVisibilityChange(this)},toggle:function(){this.setVisible(!this._isVisible)},showDeleteButton:function(e){if(this._deleteButton){this._deleteButton.style.display=!!e?"":"none"}},getParams:function(e){if(!this.isVisible()){return}if(this._controller&&this._controller.tryGetParams(e)){return}var t=BX.findChildren(this._container,{tag:/^INPUT|SELECT|TEXTAREA/i},true);for(var i=0;i<t.length;i++){var n=t[i];var s=n.name;if(s===""){continue}switch(n.type.toLowerCase()){case"select-one":case"text":case"textarea":case"hidden":{e[s]=n.value;break}case"radio":{if(n.checked){e[s]=n.value}break}case"checkbox":{e[s]=n.checked?n.value:false;break}case"select-multiple":{s=s.substr(0,s.length-2);e[s]={};for(var r=0;r<n.options.length;r++){if(n.options[r].selected&&n.options[r].value){e[s]["sel"+n.options[r].value]=n.options[r].value}}break}}}},setParams:function(e){if(this._controller&&this._controller.trySetParams(e)){return}var t=BX.findChildren(this._container,{tag:/^INPUT|SELECT|TEXTAREA/i},true);var i=false;for(var n=0;n<t.length;n++){var s=t[n];var r=s.name;if(r===""){continue}var a=false;var l=typeof e[r]!=="undefined"?e[r]:null;switch(s.type.toLowerCase()){case"select-one":case"text":case"textarea":case"hidden":s.value=l!==null?l:"";a=true;break;case"select-multiple":{r=r.substr(0,r.length-2);l=typeof e[r]==="object"&&e[r]?e[r]:{};if(l===null){for(var o=0;o<s.options.length;o++){s.options[o].selected=false}}else{var d=false;for(var h=0;h<s.options.length;h++){var f=s.options[h];var c="sel"+f.value;var u=l[c]?l[c]:null;f.selected=f.value==u;if(f.value==u){d=true}}if(!d&&s.options.length>0&&s.options[0].value==""){s.options[0].selected=true}}a=true;break}case"radio":case"checkbox":{s.checked=l!==null?l:false}a=true;break}if(a){if(!i){i=true}if(BX.type.isFunction(s.onchange)){try{s.onchange()}catch(g){}}}}if(i&&this._controller&&BX.type.isFunction(this._controller.handleParamsChange)){this._controller.handleParamsChange()}}};BX.InterfaceGridFilterField.convertParamToFieldId=function(e){return e.replace(/_[a-z]+$/,"")};BX.InterfaceGridFilterField.create=function(e,t){var i=new BX.InterfaceGridFilterField;i.initialize(e,t);return i}}if(typeof BX.InterfaceGridFilterDate==="undefined"){BX.InterfaceGridFilterDate=function(){this._settings=null;this._container=null};BX.InterfaceGridFilterDate.prototype={initialize:function(e){this._settings=e?e:BX.ParamBag.create(null);this._container=BX(e.getParam("containerId"));var t=BX.findChild(this._container,{tag:"SELECT","class":"bx-filter-date-interval-select"},true,false);if(t){BX.bind(t,"change",BX.delegate(this._onIntervalChange,this))}BX.bind(BX.findChild(BX.findChild(this._container,{tag:"DIV","class":"bx-filter-date-from"},true,false),{tag:"SPAN","class":"bx-calendar-icon"},true,false),"click",BX.delegate(this._onDataFromClick,this));BX.bind(BX.findChild(BX.findChild(this._container,{tag:"DIV","class":"bx-filter-date-to"},true,false),{tag:"SPAN","class":"bx-calendar-icon"},true,false),"click",BX.delegate(this._onDataToClick,this))},_openCalendar:function(e,t){BX.calendar({node:e,field:t,form:this._settings.getParam("formName"),bTime:false,currentTime:this._settings.getParam("currentTime"),bHideTime:false})},_onIntervalChange:function(e){this.layout()},_onDataFromClick:function(e){var t=BX.findChild(this._container,{tag:"DIV","class":"bx-filter-date-from"},true,false);if(!t){return}this._openCalendar(BX.findChild(t,{tag:"SPAN","class":"bx-calendar-icon"},true,false),BX.findChild(t,{tag:"INPUT","class":"bx-input-date"},true,false))},_onDataToClick:function(e){var t=BX.findChild(this._container,{tag:"DIV","class":"bx-filter-date-to"},true,false);if(!t){return}this._openCalendar(BX.findChild(t,{tag:"SPAN","class":"bx-calendar-icon"},true,false),BX.findChild(t,{tag:"INPUT","class":"bx-input-date"},true,false))},_displayNode:function(e,t){var i=BX.findChild(this._container,e,true,false);if(i){i.style.display=t?"":"none"}},layout:function(){var e=BX.findChild(this._container,{tag:"SELECT","class":"bx-filter-date-interval-select"},true,false);if(!e){return}var t,i,n,s;t=i=n=s=false;var r=e.value;if(r==="interval"){t=i=n=true}else if(r==="before"){i=true}else if(r==="after"||r==="exact"){t=true}else if(r==="days"){s=true}this._displayNode({tag:"DIV","class":"bx-filter-date-days"},s);this._displayNode({tag:"DIV","class":"bx-filter-date-days-suffix"},s);this._displayNode({tag:"DIV","class":"bx-filter-date-from"},t);this._displayNode({tag:"DIV","class":"bx-filter-date-to"},i);this._displayNode({tag:"SPAN","class":"bx-filter-calendar-separate"},n)},tryGetParams:function(e){return false},trySetParams:function(e){return false},handleParamsChange:function(){this.layout()}};BX.InterfaceGridFilterDate.create=function(e){var t=new BX.InterfaceGridFilterDate;t.initialize(e);return t}}if(typeof BX.InterfaceGridFilterUser==="undefined"){BX.InterfaceGridFilterUser=function(){this._settings=null;this._info=null;this._container=null};BX.InterfaceGridFilterUser.prototype={initialize:function(e){this._settings=e?e:BX.ParamBag.create(null);this._container=BX(e.getParam("containerId"));this._info=e.getParam("info",null)},layout:function(){},trySetParams:function(e){if(!this._info){return false}var t=this._info["params"]?this._info["params"]:{};var i=t["data"]?t["data"]:{};this._setElementByParam(i["elementId"],i["paramName"],e);var n=t["search"]?t["search"]:{};this._setElementByParam(n["elementId"],n["paramName"],e);return true},tryGetParams:function(e){return false},_setElementByParam:function(e,t,i){var n=BX.type.isNotEmptyString(e)?BX(e):null;if(BX.type.isElementNode(n)){n.value=BX.type.isNotEmptyString(t)&&i[t]?i[t]:""}}};BX.InterfaceGridFilterUser.create=function(e){var t=new BX.InterfaceGridFilterUser;t.initialize(e);return t}}if(typeof BX.InterfaceGridFilterWidgetPeriod==="undefined"){BX.InterfaceGridFilterWidgetPeriod=function(){this._settings=null;this._info=null;this._container=null;this._editor=null;this._editorId="";this._elementId="";this._editorChangeListener=BX.delegate(this.onEditorChange,this)};BX.InterfaceGridFilterWidgetPeriod.prototype={initialize:function(e){this._settings=e?e:BX.ParamBag.create(null);this._container=BX(e.getParam("containerId"));this._info=e.getParam("info",null);if(this._info){this._editorId=this._info["params"]["editor"]["id"];this._elementId=this._info["params"]["data"]["elementId"]}if(typeof BX.CrmWidgetConfigPeriodEditor!=="undefined"){if(typeof BX.CrmWidgetConfigPeriodEditor.items[this._editorId]!=="undefined"){this.setEditor(BX.CrmWidgetConfigPeriodEditor.items[this._editorId])}else{BX.addCustomEvent(window,"CrmWidgetConfigPeriodEditorCreate",BX.delegate(this.onEditorCreate,this))}}},layout:function(){},trySetParams:function(e){var t=this._info["params"]["data"];var i=e[t["paramName"]]?e[t["paramName"]]:"";if(this._editor){this._editor.removeChangeListener(this._editorChangeListener);var n=this.internalizeConfig(i);this._editor.setPeriod(n["period"]);if(BX.type.isNumber(n["year"])){this._editor.setYear(n["year"])}if(BX.type.isNumber(n["quarter"])){this._editor.setQuarter(n["quarter"])}if(BX.type.isNumber(n["month"])){this._editor.setMonth(n["month"])}this._editor.addChangeListener(this._editorChangeListener)}var s=BX(this._elementId);if(BX.type.isElementNode(s)){s.value=i}return true},tryGetParams:function(e){e[this._info["params"]["data"]["paramName"]]=this.getValue();return true},setEditor:function(e){if(this._editor){this._editor.removeChangeListener(this._editorChangeListener)}this._editor=e;if(this._editor){this._editor.addChangeListener(this._editorChangeListener)}},getValue:function(){if(!this._editor){return""}return this.externalizeConfig({period:this._editor.getPeriod(),year:this._editor.getYear(),quarter:this._editor.getQuarter(),month:this._editor.getMonth()})},internalizeConfig:function(e){var t=new Date;var i=t.getFullYear();var n=t.getMonth()+1;var s=n>=10?4:n>=7?3:n>=4?2:1;var r={period:BX.CrmWidgetFilterPeriod.undefined};var a=e.split("-");if(a.length>0){r["period"]=a[0]}if(r["period"]===BX.CrmWidgetFilterPeriod.year||r["period"]===BX.CrmWidgetFilterPeriod.quarter||r["period"]===BX.CrmWidgetFilterPeriod.month){r["year"]=a.length>1?parseInt(a[1]):i}if(r["period"]===BX.CrmWidgetFilterPeriod.quarter){r["quarter"]=a.length>2?parseInt(a[2]):s}else if(r["period"]===BX.CrmWidgetFilterPeriod.month){r["month"]=a.length>2?parseInt(a[2]):n}return r},externalizeConfig:function(e){var t=e["period"];var i=e["year"];var n=e["quarter"];var s=e["month"];if(t===BX.CrmWidgetFilterPeriod.year){return t+"-"+i}else if(t===BX.CrmWidgetFilterPeriod.quarter){return t+"-"+i+"-"+n}else if(t===BX.CrmWidgetFilterPeriod.month){return t+"-"+i+"-"+s}return t},onEditorCreate:function(e){if(this._editorId===e.getId()){this.setEditor(e)}},onEditorChange:function(e){var t=BX(this._elementId);if(BX.type.isElementNode(t)){t.value=this.getValue()}}};BX.InterfaceGridFilterWidgetPeriod.create=function(e){var t=new BX.InterfaceGridFilterWidgetPeriod;t.initialize(e);return t}}if(typeof BX.InterfaceGridFilterSaveAsDialog==="undefined"){BX.InterfaceGridFilterSaveAsDialog=function(){this._id="";this._settings=null;this._filter=null;this._dlg=null;this._buttonId="";this._nameInput=null};BX.InterfaceGridFilterSaveAsDialog.prototype={initialize:function(e,t){this._id=e;this._settings=t?t:BX.ParamBag.create(null);this._filter=t.getParam("filter",null)},getId:function(){return this._id},getButtonId:function(){return this._buttonId},getValues:function(){return{name:this._nameInput?this._nameInput.value:""}},openDialog:function(){if(this._dlg){this._dlg.show();return}this._dlg=new BX.PopupWindow(this.getId()+"_SAVE_AS",null,{autoHide:false,draggable:true,offsetLeft:0,offsetTop:0,bindOptions:{forceBindPosition:false},closeByEsc:true,closeIcon:true,titleBar:BX.InterfaceGridFilter.getMessage("saveAsDialogTitle"),events:{onPopupClose:BX.delegate(this._handleDialogClose,this)},content:this._prepareContent(),buttons:this._prepareButtons()});this._dlg.show()},_prepareContent:function(){var e=BX.create("TABLE",{style:{width:"350px",margin:"5px 0 0 0"}});var t=e.insertRow(-1);var i=t.insertCell(-1);i.align="right";i.innerHTML=BX.InterfaceGridFilter.getMessage("saveAsDialogFieldName")+":";i=t.insertCell(-1);this._nameInput=BX.create("INPUT",{style:{width:"200px"},props:{type:"text",maxlength:"255",size:"30"},text:BX.InterfaceGridFilter.getMessage("defaultFilterName")
});i.appendChild(this._nameInput);return e},_prepareButtons:function(){return[new BX.PopupWindowButton({text:BX.InterfaceGridFilter.getMessage("buttonSave"),className:"popup-window-button-accept",events:{click:BX.delegate(this._handleSaveButtonClick,this)}}),new BX.PopupWindowButtonLink({text:BX.InterfaceGridFilter.getMessage("buttonCancel"),className:"popup-window-button-link-cancel",events:{click:BX.delegate(this._handleCancelButtonClick,this)}})]},_handleSaveButtonClick:function(e){this._buttonId="save";this._filter.handleSaveAsDialogClose(this);this._dlg.close()},_handleCancelButtonClick:function(e){this._buttonId="cancel";this._filter.handleSaveAsDialogClose(this);this._dlg.close()},_handleDialogClose:function(e){if(this._dlg){this._dlg.destroy()}this._dlg=null}};BX.InterfaceGridFilterSaveAsDialog.create=function(e,t){var i=new BX.InterfaceGridFilterSaveAsDialog;i.initialize(e,t);return i}}if(typeof BX.InterfaceGridFilterCheckListMenu==="undefined"){BX.InterfaceGridFilterCheckListMenu=function(){this._id="";this._settings=null;this._filter=null;this._allowToggle=true;this._items=[];this._menuId="";this._menu=null};BX.InterfaceGridFilterCheckListMenu.prototype={initialize:function(e,t){this._id=e;this._menuId=this._id.toLowerCase();this._settings=t?t:BX.ParamBag.create(null);this._filter=t.getParam("filter",null);this._allowToggle=this.getSetting("allowToggle",true);this._closeOnClick=this.getSetting("closeOnClick",false);var i=this.getSetting("items");for(var n=0;n<i.length;n++){var s=i[n];this._items.push(BX.InterfaceGridFilterCheckListMenuItem.create(s["id"],BX.ParamBag.create({text:BX.type.isString(s["text"])?s["text"]:"",checked:BX.type.isBoolean(s["checked"])?s["checked"]:false,tag:BX.type.isNotEmptyString(s["tag"])?s["tag"]:"",onchange:BX.type.isFunction(s["onchange"])?s["onchange"]:null,onclick:BX.type.isFunction(s["onclick"])?s["onclick"]:null,allowToggle:BX.type.isBoolean(s["allowToggle"])?s["allowToggle"]:this._allowToggle,closeOnClick:BX.type.isBoolean(s["closeOnClick"])?s["closeOnClick"]:this._closeOnClick,separatorBefore:BX.type.isBoolean(s["separatorBefore"])?s["separatorBefore"]:false,separatorAfter:BX.type.isBoolean(s["separatorAfter"])?s["separatorAfter"]:false,menu:this})))}},getId:function(){return this._id},getSetting:function(e,t){return this._settings.getParam(e,t)},open:function(){var e=[];for(var t=0;t<this._items.length;t++){var i=this._items[t].createPopupMenuItems();for(var n=0;n<i.length;n++){e.push(i[n])}}if(typeof BX.PopupMenu.Data[this._menuId]!=="undefined"){BX.PopupMenu.Data[this._menuId].popupWindow.destroy();delete BX.PopupMenu.Data[this._menuId]}this._menu=BX.PopupMenu.show(this._menuId,this.getSetting("anchor",null),e,{offsetTop:parseInt(this.getSetting("offsetTop",0)),offsetLeft:parseInt(this.getSetting("offsetLeft",0)),angle:this.getSetting("angle",{})})},close:function(){if(typeof BX.PopupMenu.Data[this._menuId]!=="undefined"){BX.PopupMenu.Data[this._menuId].popupWindow.close()}},getItemsByTag:function(e){var t=[];for(var i=0;i<this._items.length;i++){var n=this._items[i];if(n.getTag()===e){t.push(n)}}return t},getContainer:function(){return BX("menu-popup-"+this.getId().toLowerCase())}};BX.InterfaceGridFilterCheckListMenu.create=function(e,t){var i=new BX.InterfaceGridFilterCheckListMenu;i.initialize(e,t);return i}}if(typeof BX.InterfaceGridFilterCheckListMenuItem==="undefined"){BX.InterfaceGridFilterCheckListMenuItem=function(){this._id="";this._settings=null;this._menu=null;this._checked=false;this._tag="";this._allowToggle=true;this._closeOnClick=false};BX.InterfaceGridFilterCheckListMenuItem.prototype={initialize:function(e,t){this._id=e;this._settings=t?t:BX.ParamBag.create(null);this._menu=t.getParam("menu",null);this._checked=t.getParam("checked",false);this._tag=this.getSetting("tag","");this._allowToggle=this.getSetting("allowToggle",true);this._closeOnClick=this.getSetting("closeOnClick",false)},getSetting:function(e,t){return this._settings.getParam(e,t)},getId:function(){return this._id},getTag:function(){return this._tag},setTag:function(e){this._tag=e},isChecked:function(){return this._checked},setChecked:function(e){e=!!e;if(this._checked===e){return}this._checked=e;var t=BX.findChild(this._menu.getContainer(),{tag:"A","class":"crm-check-list-menu-item-"+this.getId().toLowerCase()},true,false);if(t){if(e){BX.addClass(t,"menu-popup-item-checked")}else{BX.removeClass(t,"menu-popup-item-checked")}}var i=this.getSetting("onchange",null);if(BX.type.isFunction(i)){try{i({id:this.getId(),checked:e},this)}catch(n){}}},isTogglable:function(){return this._allowToggle},toggle:function(){if(this._allowToggle){this.setChecked(!this.isChecked())}},createPopupMenuItems:function(){var e=[];if(this.getSetting("separatorBefore",false)){e.push({SEPARATOR:true})}e.push({text:this.getSetting("text",this.getId()),className:"crm-filter-popup-item"+(this.isChecked()?" menu-popup-item-checked":"")+" crm-check-list-menu-item-"+this.getId().toLowerCase(),href:"#",onclick:BX.delegate(this._onClick,this)});if(this.getSetting("separatorAfter",false)){e.push({SEPARATOR:true})}return e},_onClick:function(e){BX.PreventDefault(e);var t=this.getSetting("onclick",null);if(BX.type.isFunction(t)){try{t({id:this.getId(),checked:this.isChecked()},this)}catch(i){}}if(this._closeOnClick){this._menu.close();return}this.toggle()}};BX.InterfaceGridFilterCheckListMenuItem.create=function(e,t){var i=new BX.InterfaceGridFilterCheckListMenuItem;i.initialize(e,t);return i}}if(typeof BX.InterfaceGridFilterCloseOpen==="undefined"){BX.InterfaceGridFilterCloseOpen=function(e,t,i){this.filter=i;this.innerBlock=BX(e);this.mainBlock=BX(t);this.isOpen=null};BX.InterfaceGridFilterCloseOpen.prototype={initialize:function(){this.isOpen=!this.filter.isFolded()},_easing:function(e){var t=this;var i=new BX.easing({duration:300,start:{height:e.start},finish:{height:e.finish},transition:BX.easing.makeEaseOut(BX.easing.transitions.circ),step:BX.delegate(this._step,this),complete:BX.proxy(this._complete,this)});i.animate()},toggle:function(){if(this.isOpen){this._easing({start:this.innerBlock.offsetHeight,finish:0});this.isOpen=false}else{this._easing({start:this.mainBlock.offsetHeight,finish:this.innerBlock.offsetHeight});this.isOpen=true}},_step:function(e){this.mainBlock.style.height=e.height+"px"},_complete:function(){if(this.isOpen)this.mainBlock.style.height="auto"}}}if(typeof BX.InterfaceGridFilterNavigationBar==="undefined"){BX.InterfaceGridFilterNavigationBar=function(){this._id="";this._settings=null;this._binding=null;this._items=null};BX.InterfaceGridFilterNavigationBar.prototype={initialize:function(e,t){this._id=e;this._settings=t?t:BX.ParamBag.create(null);this._binding=this.getSetting("binding",null);this._items=[];var i=this.getSetting("items",[]);for(var n=0;n<i.length;n++){var s=i[n];var r=BX.type.isNotEmptyString(s["id"])?s["id"]:n;s["parent"]=this;this._items.push(BX.InterfaceGridFilterNavigationBarItem.create(r,BX.ParamBag.create(s)))}},getId:function(){return this._id},getSetting:function(e,t){return this._settings.getParam(e,t)},getBinding:function(){return this._binding}};BX.InterfaceGridFilterNavigationBar.create=function(e,t){var i=new BX.InterfaceGridFilterNavigationBar;i.initialize(e,t);return i}}if(typeof BX.InterfaceGridFilterNavigationBarItem==="undefined"){BX.InterfaceGridFilterNavigationBarItem=function(){this._id="";this._settings=null;this._parent=null;this._button=null;this._hint=null;this._buttonHandler=BX.delegate(this.onButtonClick,this)};BX.InterfaceGridFilterNavigationBarItem.prototype={initialize:function(e,t){this._id=e;this._settings=t?t:BX.ParamBag.create(null);this._parent=this.getSetting("parent");if(!this._parent){throw"InterfaceGridFilterNavigationBarItem: The parameter 'parent' is not found."}this._button=BX(this.getSetting("buttonId"));if(!this._button){throw"InterfaceGridFilterNavigationBarItem: The button element is not found."}BX.bind(this._button,"click",this._buttonHandler);if(this.getSetting("enableHint",true)){this.createHint(this.getSetting("hint",null))}},getId:function(){return this._id},getSetting:function(e,t){return this._settings.getParam(e,t)},createHint:function(e){if(!e){return}this._hint=BX.PopupWindowManager.create(this._id+"_hint",this._button,{offsetTop:-8,autoHide:true,closeByEsc:false,angle:{position:"bottom",offset:42},events:{onPopupClose:BX.delegate(this.onHintClose,this)},content:BX.create("DIV",{attrs:{className:"crm-popup-contents"},children:[BX.create("SPAN",{attrs:{className:"crm-popup-title"},text:e["title"]}),BX.create("P",{text:e["content"]}),BX.create("P",{children:[BX.create("A",{props:{href:"#"},text:e["disabling"],events:{click:BX.delegate(this.onDisableHint,this)}})]})]})});this._hint.show()},onButtonClick:function(e){var t=this.getSetting("url","");if(t===""){return}var i=this._parent.getBinding();if(i){var n=BX.type.isNotEmptyString(i["category"])?i["category"]:"";var s=BX.type.isNotEmptyString(i["name"])?i["name"]:"";var r=BX.type.isNotEmptyString(i["key"])?i["key"]:"";if(n!==""&&s!==""&&r!==""){BX.userOptions.save(n,s,r,this._id,false)}}setTimeout(function(){window.location.href=t},150)},onDisableHint:function(e){if(this._hint){this._hint.close();BX.userOptions.save("main.interface.filter.navigation",this._parent.getId().toLowerCase(),"enable_"+this._id.toLowerCase()+"_hint","N",false)}return BX.PreventDefault(e)},onHintClose:function(){if(this._hint){this._hint.destroy();this._hint=null}}};BX.InterfaceGridFilterNavigationBarItem.create=function(e,t){var i=new BX.InterfaceGridFilterNavigationBarItem;i.initialize(e,t);return i}}
//# sourceMappingURL=script.map.js